var bip39 = require('bip39')
var hdkey = require('ethereumjs-wallet/hdkey')
var util = require('ethereumjs-util')
var Tx = require('ethereumjs-tx');
var keythereum = require("keythereum");
var Web3 = require('web3');
if (typeof web3 !== 'undefined') {
  web3 = new Web3(web3.currentProvider);
} else {
  // set the provider you want from Web3.providers
  web3 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io/H2RvEhIXzZSxx73jLtcZ"));
}
var keythereum = require("keythereum");

//var message = "deadbeaf"
//var hasmsg = '0x' +web3.utils.sha3(message)
//var hasmsg = web3.utils.sha3('\u0019Ethereum Signed Message:\n' + message.length.toString()+message)
//console.log(util.toBuffer(hasmsg))
//var s = "\x19Ethereum Signed Message:\n" + message.length + message
//const msgHash  = util.hashPersonalMessage(Buffer.from(message,'hex'))
var a = Buffer.from("ca1ad489ab60ea581e6c119cc39d94ddbfc5faa0e178a23ca66202c8c2a72277",'hex');
var r = Buffer.from("bff7a2d5d68d5d144adb191d2d2ded526b9e9fa1a4ed0ae9aa21adeff251e817",'hex');
var s = Buffer.from("2718cc7da62ea694d22873142b62dcea9110d32208e685bb79cafcc86bbc9824",'hex');
var v = 28;


//const senderPubKey = secp256k1.recover(msgHash, signature, recovery)
//  return secp256k1.publicKeyConvert(senderPubKey, false).slice(1)

var publicAddress = util.ecrecover(a,v,r,s)
console.log(publicAddress.toString('hex'))

//fddf78da017d8cac8a825536e8a903d9c8fc8b51a4245e08414e3b905de900029f76f869f9e001111edfe82e77f10d0d6e52b858f1c6e789ae41d3e348bf08cc
//7f7d8e7f7045636a1c954dd19d83b0f045141e31159de1a9a4d85b9c86882abd1d7517f34a1c15ee
//4da1faf9a898a97667a4567647dc729b4adcc052be8f0ed4
//27
//0x9eda0abaa6ae0c7647a1a449f3903a53387b6f5375eb927775605601d201cc8577855a1f3be83f92d27e61e4989e9fdea0af4f16bd5f497065eee0b026ac1a0f1b

//bff7a2d5d68d5d144adb191d2d2ded526b9e9fa1a4ed0ae9aa21adeff251e817
//2718cc7da62ea694d22873142b62dcea9110d32208e685bb79cafcc86bbc9824
//1c
//    7f7d8e7f7045636a1c954dd19d83b0f045141e31159de1a9a4d85b9c86882abd1d7517f34a1c15ee
//99eb120431db60c5cab6db78f6b4dbaa7eb8ccd50c406e2f91db2b6c6fdbc6bef73790e7d0ea155e8d882f2a4f19fd05d937169c1705633503d3c7ce5225e4dd
//ca1ad489ab60ea581e6c119cc39d94ddbfc5faa0e178a23ca66202c8c2a72277ca1ad489ab60ea581e6c119cc39d94ddbfc5faa0e178a23ca66202c8c2a72277
//0499eb120431db60c5cab6db78f6b4dbaa7eb8ccd50c406e2f91db2b6c6fdbc6bef73790e7d0ea155e8d882f2a4f19fd05d937169c1705633503d3c7ce5225e4dd
